//
//  ViewController.m
//  11-23
//
//  Created by Mac OS on 15-11-23.
//
//

#import "ViewController.h"
#import "InputTableViewController.h"
@interface ViewController ()<InputFinshiDelegate>
{
    NSArray * data;
    NSArray * tels;
    NSIndexPath * curIndexPath;
}
@end

@implementation ViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    data = @[
             @"张三",
             @"王二",
             @"李四",
             @"王五",
             @"马仔",
             ];
    tels = @[
             @"13578956235",
             @"13245879564",
             @"14756923546",
             @"15673603439",
             @"15096301168",
             ];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    
    cell.textLabel.text = data[indexPath.row];
    
    cell.detailTextLabel.text = tels[indexPath.row];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    InputTableViewController *con = [[InputTableViewController alloc]initWithStyle:UITableViewStylePlain];
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    con.tel = cell.detailTextLabel.text;
    con.delegate = self;
    curIndexPath = indexPath;
    
    //con.tel = tels[indexPath.row];
    [self.navigationController pushViewController:con animated:YES];
}

- (void)inputFinished:(NSString *)text
{
    NSLog(@"indexPath:%@",[self.tableView indexPathForSelectedRow]);
    NSMutableArray *arr = tels.mutableCopy;
    [arr replaceObjectAtIndex:curIndexPath.row withObject:text];
    tels = arr;
    [self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
